package com.zhiyou.service.Rent;



import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.zhiyou.bean.Rent;
import com.zhiyou.dao.RentMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


import java.util.List;

@Service
public class RentserviceImpl implements Rentservice{

    @Autowired
    RentMapper rentMapper;

    @Override
    public List<Rent> selectGetAll(Integer pn) {
        PageHelper.startPage(pn,5);
        List<Rent> rent = rentMapper.selectRentAllAndHouse();
        PageInfo<Rent> info = new PageInfo<>(rent, 5);
        return rent;
    }
    @Override
    public List<Rent> getAllDetail(String pn) {
        List<Rent> rent = rentMapper.selectGetAlldetail(pn);
        return rent;
    }

    @Override



    public List<Rent> getAllEdit(String pn) {
        List<Rent> rent = rentMapper.selectGetEdit(pn);
        return rent;
    }

    @Override
    public int UpdateRent(Rent rent) {
        int i = rentMapper.updateByPrimaryKeySelective(rent);
        return i;
    }

    @Override
    public int AddRent(Rent rent) {
        int insert = rentMapper.insert(rent);
        return insert;
    }

    @Override
    public int DeleteRent(String rid) {
        int delete = rentMapper.deleteByPrimaryKey(rid);
        return delete;
    }

    public List<Rent> getLikeRent(String field,String ID ){
        Rent ren = new Rent();
        if(!ID.isEmpty()){
            switch (field){
                case "lId":
                    ren.setlId(Integer.valueOf(ID));
                    break;
                case "rId":
                    ren.setrId(Integer.valueOf(ID));
                    break;
                case "hId":
                    ren.sethId(Integer.valueOf(ID));
                    break;
            }
        }
        return rentMapper.selectLikeRent(ren);
    }

    @Override
    public List<Rent> selectGetAll() {
        List<Rent> rents = rentMapper.selectRentAllAndHouse();
        return rents;
    }

}
